var pageNo2="1";
var pageSize2="10";
var totalPage_myReview2="0";
var page_con=true;
$( document ).on( "pagecreate", "#myReview", function( event ) {
	$(".tab").lt_tab({
		minItems: 2,
		changeMode : "click",
		callBack:function(currentIndex){
			console.log(currentIndex);
		}
	});  
});
$( document ).on( "pageshow", "#myReview", function( event ) {
	access_token=getQueryString("access_token");
	pageNo="1";
	pageSize="10";
	
	$("#wrapper_myReview  #pullDown").hide();
	$("#wrapper_page2  #pullDown2").hide();
	
	var scrollObj_myReview=scrollPlugLoadedOfReturn("wrapper_myReview",
			function() {
				setTimeout(function () {
					if(pageNo >= totalPage)
						return;
					pageNo++;
					loadData_myReview(false,scrollObj_myReview);
				}, 1000);	
			},
			function() {
//				setTimeout(function () {
//					pageNo=1;
//					loadData_myReview(true);
//				}, 1000);
				scrollObj_myReview.refresh();
			});
	
	loadData_myReview(true,scrollObj_myReview);
	
	
	$( "#selected_two" ).on("click",function (){
		loadSelected_two_fun();
	});
	
});


function loadSelected_two_fun(){
	var loadData_2=function (){
		pageNo2="1";
		pageSize2="10";
		totalPage_myReview2="0";
		loadData_myReview2(true);
	};
	setTimeout(loadData_2, 100); 
	var pageLoad2=function(){
		scrollPlugLoaded2("wrapper_page2",function(){
//			setTimeout(function () {
//				pageNo2=1;
//				loadData_myReview2(true);
//			}, 1000);
		},function(){
			setTimeout(function () {
				if(totalPage_myReview2>pageNo2){
					pageNo2++;
					loadData_myReview2();
				}
			}, 1000);	
		});
	};
	setTimeout(pageLoad2, 10); 
}

function p_show(obj){
	var c = $(obj).css("white-space");
	if(c == 'normal'){
		$(obj).css({"white-space":"nowrap"});
	}else{
		$(obj).css({"white-space":"normal"});
	}	
}

/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_myReview(isFresh,scrollObj_myReview){
	$.ajax({
	  	url: rootPath+"/review/myReviews.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&pageNo="+pageNo+"&pageSize="+pageSize,
	  	success: function( response ) {
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
		  		
				var content = "";
				for (var i=0;i<arr.length;i++){
//					content +='<li>\
//						  <a href="#" style="padding-left: 60px;">\
//							<img style="top: 0.4em;" src="'+rootPath+"/images/weixin/defualt.jpg"+'" class="ui-li-icon">\
//							<p>'+arr[i].criticsName+' 送 '+arr[i].byCriticsName+' 一朵红花<strong class="ui-li-aside">'+arr[i].create_time+'</strong></p>\
//							<p onclick="p_show(this)">'+arr[i].reviewContent+'</p>\
//						  </a>\
//						</li>';	
					content+='<li>\
										<div class="table_cell">\
											<dl style="padding:0;margin-top:0;">\
												<dd style="padding-right:20px">\
													<span class="table_cell_text">\
														<span class="text_strong">我</span>送给<span class="text_strong">'+arr[i].byCriticsName+'</span>一朵\
															<img src="'+rootPath+flower_+'"/>\
														<span class="table_cell_name_datetime">'+arr[i].create_timeStr+'</span>\
													</span>\
													<span class="table_cell_content" ><p onclick="p_show(this)">'+replaceContent(arr[i].reviewContent)+'</p></span>\
												</dd>\
											</dl>\
										</div>\
										<div class="clear"></div>\
									</li>';
				}
				if(arr.length<pageSize){
					$("#wrapper_myReview  #pullUp").hide();
				}else{
					$("#wrapper_myReview  #pullUp").show();
				}
				if(isFresh && $("#thelist_myReview").html()!=""){
					$("#thelist_myReview").html("");
				}
				$("#thelist_myReview").append(content).listview('refresh');
				scrollObj_myReview.refresh();
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}



/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_myReview2(isFresh,isInit){
	$.ajax({
	  	url: rootPath+"/review/reviewMeInfos.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&pageNo="+pageNo+"&pageSize="+pageSize,
	  	success: function( response ) {
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				 totalPage_myReview2=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
				var content = "";
				for (var i=0;i<arr.length;i++){
//					content +='<li>\
//						  <a href="#" style="padding-left: 60px;">\
//							<img style="top: 0.4em;" src="'+rootPath+"/images/weixin/defualt.jpg"+'" class="ui-li-icon">\
//							<p>'+arr[i].criticsName+' 送 '+arr[i].byCriticsName+' 一朵红花<strong class="ui-li-aside">'+arr[i].create_time+'</strong></p>\
//							<p onclick="p_show(this)">'+arr[i].reviewContent+'</p>\
//						  </a>\
//						</li>';
					content+='<li>\
						<div class="table_cell">\
							<dl style="padding:0;margin-top:0;">\
								<dd style="padding-right:20px">\
									<span class="table_cell_text">\
										<span class="text_strong">'+arr[i].criticsName+'</span>送给<span class="text_strong"> 我</span>一朵\
										<img src="'+rootPath+flower_+'"/>\
										<span class="table_cell_name_datetime">'+arr[i].create_timeStr+'</span>\
									</span>\
									<span class="table_cell_content" ><p onclick="p_show(this)">'+replaceContent(arr[i].reviewContent)+'</p></span>\
								</dd>\
							</dl>\
						</div>\
						<div class="clear"></div>\
					</li>';
				}
				if(arr.length<pageSize2){
					$("#pullUp2").hide();
				}else{
					$("#pullUp2").show();
				}
				if(isFresh && $("#thelist_page2").html()!=""){
					$("#thelist_page2").html("");
				}
				$("#thelist_page2").append(content).listview('refresh');
				myScroll2.refresh();
			}else{
				alert(data.msg);
			}
	  	}
	});
}